package cdu.javaendwork.service.Impl.User;

import cdu.javaendwork.dao.Universal;
import cdu.javaendwork.dao.impl.UniversalImpl;
import cdu.javaendwork.model.sqlModel.Concern;
import cdu.javaendwork.service.Interface.User.ConcernService;

import java.util.List;

public class ConcernServiceImpl implements ConcernService {

    Universal universal = new UniversalImpl();

    // 添加一条关注信息
    @Override
    public boolean insert(int userid, int concernid) {

        return universal.insert("Concern", userid, concernid)==1;
    }

    // 删除一条关注信息
    @Override
    public boolean delete(int id) {

        return universal.deleteById("Concern",id)==1;
    }

    // 分页查询该用户的所有关注信息
    @Override
    public List<Concern> concernLimit(int userid, int pageIndex, int pageSize) {

        return universal.filterLimit("Concern", "userid="+userid, pageIndex, pageSize);
    }

    // 查询该用户关注的用户的数量
    @Override
    public int concernCnt(int userid) {

        return universal.filterFindSumCount("Concern", "userid="+userid);
    }

    // 分页查询该用户被关注的所有信息
    @Override
    public List<Concern> concernedLimit(int concernid, int pageIndex, int pageSize) {

        return universal.filterLimit("Concern", "concernid="+concernid, pageIndex, pageSize);
    }

    // 查询该用户被关注的数量
    @Override
    public int concernedCnt(int concernid) {

        return universal.filterFindSumCount("Concern", "concernid="+concernid);
    }
    // 判断某人是否关注某人
    @Override
    public boolean isConcerned(int userid , int concernid)
    {
        List<Concern> list = universal.filter("Concern","userid="+userid+" and concernid="+concernid);
        return !list.isEmpty();
    }

    @Override
    public Concern findByuserAndConcernId(int userid,int concernid) {
        List<Concern> concernList= universal.filter("Concern","userid="+userid+" and concernid="+concernid);
        if(concernList.isEmpty()){
            return null;
        }else {
            return concernList.get(0);
        }
    }
}
